package com.stevenmoon.csdnplus.logic;


import com.google.gson.reflect.TypeToken;
import com.stevenmoon.csdnplus.app.Constants.CSDNURL;
import com.stevenmoon.csdnplus.bean.ResponseResultBean;
import com.stevenmoon.csdnplus.bean.bbs.ForumInfo;
import com.stevenmoon.csdnplus.bean.bbs.ForumMemberInfo;
import com.stevenmoon.csdnplus.bean.bbs.ForumOperationReqBean;
import com.stevenmoon.csdnplus.bean.bbs.ForumPostAddReqBean;
import com.stevenmoon.csdnplus.bean.bbs.ForumPostInfo;
import com.stevenmoon.csdnplus.bean.bbs.ForumPostOperationReqBean;
import com.stevenmoon.csdnplus.bean.bbs.ForumPostReqBean;
import com.stevenmoon.csdnplus.bean.bbs.ForumTopicAddReqBean;
import com.stevenmoon.csdnplus.bean.bbs.ForumTopicDetailInfo;
import com.stevenmoon.csdnplus.bean.bbs.ForumTopicInfo;
import com.stevenmoon.csdnplus.net.RequestParams;
import com.stevenmoon.csdnplus.net.RxNet;
import com.stevenmoon.csdnplus.util.GsonUtil;

import java.util.List;

import rx.Observable;

/**
 * Created by WangJun on 2016/5/7.
 */
public class BBSManager {

    public Observable<Boolean> canCreateTopic(String username){
        RequestParams rp = new RequestParams(CSDNURL.BBS_CAN_CREATE_TOPIC);
        rp.put("username",username);
        return RxNet.getAndFetchEntity(rp,new TypeToken<ResponseResultBean<Boolean>>(){});
    }

    public Observable<List<ForumInfo>> getMyFavoriteForums(){
        RequestParams rp = new RequestParams(CSDNURL.BBS_FAVORITE_FORUM);
        return RxNet.getAndFetchEntity(rp,new TypeToken<ResponseResultBean<List<ForumInfo>>>(){});
    }

    public Observable<List<ForumInfo>> getAllForums(){
        RequestParams rp = new RequestParams(CSDNURL.BBS_ALL_FORUMS);
        return RxNet.getAndFetchEntity(rp,new TypeToken<ResponseResultBean<List<ForumInfo>>>(){});
    }

    public Observable<Boolean> doFavoriteForum(ForumOperationReqBean reqBean){
        RequestParams rp = new RequestParams(CSDNURL.BBS_FORUM_FAVORITE, GsonUtil.convertBean2Map(reqBean));
        return RxNet.getAndFetchEntity(rp,new TypeToken<ResponseResultBean<Boolean>>(){});
    }

    public Observable<Boolean> doUnFavoriteForum(ForumOperationReqBean reqBean){
        RequestParams rp = new RequestParams(CSDNURL.BBS_FORUM_UNFAVORITE, GsonUtil.convertBean2Map(reqBean));
        return RxNet.getAndFetchEntity(rp,new TypeToken<ResponseResultBean<Boolean>>(){});
    }

    public Observable<List<ForumTopicInfo>> getForumTopics(){
        RequestParams rp = new RequestParams(CSDNURL.BBS_TOPIC_LIST);
        return RxNet.getAndFetchEntity(rp,new TypeToken<ResponseResultBean<List<ForumTopicInfo>>>(){});
    }

    public Observable<List<ForumTopicInfo>> getHotForumTopics(){
        RequestParams rp = new RequestParams(CSDNURL.BBS_TOPIC_HOT_LIST);
        return RxNet.getAndFetchEntity(rp,new TypeToken<ResponseResultBean<List<ForumTopicInfo>>>(){});
    }

    public Observable<ForumMemberInfo> getForumMembers(String urlname){
        RequestParams rp = new RequestParams(CSDNURL.BBS_FORUM_MEMBERS);
        rp.put("urlname",urlname);
        return RxNet.getAndFetchEntity(rp,new TypeToken<ResponseResultBean<ForumMemberInfo>>(){});
    }

    public Observable<Integer> getForumScore(){
        RequestParams rp = new RequestParams(CSDNURL.BBS_SCORE);
        return RxNet.getAndFetchEntity(rp,new TypeToken<ResponseResultBean<Integer>>(){});
    }

    public Observable<ForumTopicDetailInfo> createTopic(ForumTopicAddReqBean reqBean){
        RequestParams rp = new RequestParams(CSDNURL.BBS_CREATE_TOPIC, GsonUtil.convertBean2Map(reqBean));
        return RxNet.postAndFetchEntity(rp,new TypeToken<ResponseResultBean<ForumTopicDetailInfo>>(){});
    }

    public Observable<ForumTopicDetailInfo> getTopicDetail(int topic_id){
        RequestParams rp = new RequestParams(CSDNURL.BBS_TOPIC_DETAIL);
        rp.put("topic_id",topic_id);
        return RxNet.getAndFetchEntity(rp,new TypeToken<ResponseResultBean<ForumTopicDetailInfo>>(){});
    }

    public Observable<List<ForumPostInfo>> getForumPosts(ForumPostReqBean reqBean){
        RequestParams rp = new RequestParams(CSDNURL.BBS_TOPIC_POSTS);
        return RxNet.getAndFetchEntity(rp,new TypeToken<ResponseResultBean<List<ForumPostInfo>>>(){});
    }

    public Observable<List<ForumPostInfo>> getForumLZPosts(ForumPostReqBean reqBean){
        RequestParams rp = new RequestParams(CSDNURL.BBS_TOPIC_LZ_POSTS);
        return RxNet.getAndFetchEntity(rp,new TypeToken<ResponseResultBean<List<ForumPostInfo>>>(){});
    }

    public Observable<ForumPostInfo> createTopic(ForumPostAddReqBean reqBean){
        RequestParams rp = new RequestParams(CSDNURL.BBS_CREATE_POST, GsonUtil.convertBean2Map(reqBean));
        return RxNet.postAndFetchEntity(rp,new TypeToken<ResponseResultBean<ForumPostInfo>>(){});
    }

    public Observable<ForumPostInfo> upTopicOrPost(ForumPostOperationReqBean reqBean){
        RequestParams rp = new RequestParams(CSDNURL.BBS_TOPIC_UP, GsonUtil.convertBean2Map(reqBean));
        return RxNet.postAndFetchEntity(rp,new TypeToken<ResponseResultBean<ForumPostInfo>>(){});
    }

    public Observable<ForumPostInfo> downTopicOrPost(ForumPostOperationReqBean reqBean){
        RequestParams rp = new RequestParams(CSDNURL.BBS_TOPIC_DOWN, GsonUtil.convertBean2Map(reqBean));
        return RxNet.postAndFetchEntity(rp,new TypeToken<ResponseResultBean<ForumPostInfo>>(){});
    }



}
